package com.xymtop.sqlcater.core.sql.sqlexecute.select.entity;

import lombok.Data;

@Data
public class OrderBy {

    //构造排序条件
    private SqlSelectField sqlSelectField;

    //排序的规则
    private OrderByRule orderByRule;

    public String getBuildSql(){
        String res = "ORDER BY ";
        if(sqlSelectField!=null){
            res +=  sqlSelectField.getAsName()==null?sqlSelectField.getName():sqlSelectField.getAsName();

            if(orderByRule!=null){
                if(orderByRule==OrderByRule.ASCE){
                    res += " ASCE ";
                }else {
                    res += " DESC ";
                }

            }else {
                res += " DESC ";
            }
        }
        return res;
    }
}
